package org.dromara.test

import org.dromara.common.core.enums.UserType
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource
import org.junit.jupiter.params.provider.MethodSource
import org.junit.jupiter.params.provider.NullSource
import org.junit.jupiter.params.provider.ValueSource
import java.util.stream.Stream

/**
 * 带参数单元测试案例
 *
 * @author LikeYouDo
 */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@DisplayName("带参数单元测试案例")
class ParamUnitTest {

    @DisplayName("测试 @ValueSource 注解")
    @ParameterizedTest
    @ValueSource(strings = ["t1", "t2", "t3"])
    fun testValueSource(str: String?) {
        println(str)
    }

    @DisplayName("测试 @NullSource 注解")
    @ParameterizedTest
    @NullSource
    fun testNullSource(str: String?) {
        println(str)
    }

    @DisplayName("测试 @EnumSource 注解")
    @ParameterizedTest
    @EnumSource(UserType::class)
    fun testEnumSource(type: UserType) {
        println(type.userType)
    }

    @DisplayName("测试 @MethodSource 注解")
    @ParameterizedTest
    @MethodSource("getParam")
    fun testMethodSource(str: String?) {
        println(str)
    }

    fun getParam(): Stream<String?> {
        val list: MutableList<String?> = ArrayList<String?>()
        list.add("t1")
        list.add("t2")
        list.add("t3")
        return list.stream()
    }

    @BeforeEach
    fun testBeforeEach() {
        println("@BeforeEach ==================")
    }

    @AfterEach
    fun testAfterEach() {
        println("@AfterEach ==================")
    }


}
